﻿<script>
	$('document').ready(function(){
		$('#botones_busqueda').click(function(){
			if ( validForm() ){
				$('.contact_form form').submit();
			}
		});
	});
	function validForm(){
		$('.error_message').hide();
		$allOk = true;
		
		if ($('form .name').val() == "" ){
			$('.error_message.name').show();
			$allOk = false;
		}
		
		if ($('form .email').val() == "" ){
			$('.error_message.email.required').show();
			$allOk = false;
		}else{
			var pattern = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/; 
			if ( !$('form .email').val().match(pattern) ){
				$('.error_message.email.format').show();
				$allOk = false;
			}
		}
		
		if ($('form .subject').val() == "" ){
			$('.error_message.subject').show();
			$allOk = false;
		}
		
		if ($('form .enquire').val() == "" ){
			$('.error_message.enquire').show();
			$allOk = false;
		}
		
		return $allOk;
	}
</script>
<?php
	//require '../class.phpmailer.php';
	$this->Html->addCrumb(__('Contact'));
?>
<div class="contact_page">
	<input type="hidden" id="current_tab" value="contact">
	<div class="title">
		<h1><?php echo __('Contact'); ?></h1>
	</div>
	<?php if ($show_form) { ?>
		<div class="contact_form">
			<form action="" method="post">
				<div class="field small">
					<label>Nombre y Apellido</label>
					<input class="name" type="text" name="name" value="<?php echo $data['name']; ?>">
					<div class="error_message name">Campo obligatorio</div>
				</div>
				<div class="field small">
					<label>Correo electrónico</label>
					<input class="email" type="text" name="email" value="<?php echo $data['email']; ?>">
					<div class="error_message email required">Campo obligatorio</div>
					<div class="error_message email format">Formato de correo no válido</div>
				</div>
				<div class="field small">
					<label>Teléfono</label>
					<input class="phone" type="text" name="phone" value="<?php echo $data['phone']; ?>">
				</div>
				<div class="field small">
					<label>Asunto</label>
					<?php if ( isset($prop_id) ) { ?>
					<input class="subject" type="text" name="subject" disabled="disabled" value="Consulta propiedad <?php echo $prop_id; ?>">
					<?php } 
					else { ?>
					<input class="subject" type="text" name="subject" value="<?php echo $data['subject']; ?>">
					<?php } ?>
					<div class="error_message subject">Campo obligatorio</div>
				</div>
				<div class="field large">
					<label>Consulta</label>
					<textarea class="enquire" rows="8" name="enquire"><?php echo $data['enquire']; ?></textarea>
					<div class="error_message enquire">Campo obligatorio</div>
				</div>
				<!--<div class="field button">
					<input type="button" value="Enviar consulta"/>
				</div>-->
				<div>
					<div class="error_message captcha" style="display:<?php if ($captcha_error) { echo 'block'; } else { echo 'none'; } ?>" >Por favor, Ingrese las palabras que se muestran en la siguiente imagen</div>
					<script type="text/javascript"
						src="http://www.google.com/recaptcha/api/challenge?k=6LffXuESAAAAAF-n00uthjKMTYqyt8ba4qT-DuYx">
					</script>
					<noscript>
						<iframe src="http://www.google.com/recaptcha/api/noscript?k=6LffXuESAAAAAF-n00uthjKMTYqyt8ba4qT-DuYx" height="300" width="500" frameborder="0"></iframe><br>
						<textarea name="recaptcha_challenge_field" rows="3" cols="40">
						</textarea>
						<input type="hidden" name="recaptcha_response_field" value="manual_challenge">
					</noscript>
				</div>	
				<div id="botones_busqueda">
					<span class="texto_boton_buscar">Enviar<br>consulta</span>
				</div>	
			</form>
		</div>
	<?php } 
	else { ?>
		<div class="confirmation_message">
			<label><?php echo $message_in_a_bottle; ?></label>
		</div>	
	<?php } ?>
</div>